package com.example.exam.utils;

import java.time.LocalDateTime;

/**
 * @author zhang
 */
public class RandomUtils {
    /**
     * 获取随机字符串
     * @param length 长度
     * @return 随机字符串
     */
    public static String getRandomString(int length) {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int number = (int) (Math.random() * 62);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }
    /**
     * 生成盐
     * @return 盐
     */
    public static String generateSalt() {
        return getRandomString(6);
    }

    public static String generateAccount() {
        long year = LocalDateTime.now().getDayOfYear();
        long time = System.currentTimeMillis() % 100000;
        return String.valueOf(year) + time;
    }
}
